﻿package mortal.game.view.copy.guildCopy
{
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.gengine.utils.*;
    import com.greensock.*;
    import com.greensock.easing.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import fl.data.*;
    import flash.utils.*;
    import mortal.common.global.*;
    import mortal.common.swfPlayer.*;
    import mortal.common.swfPlayer.data.*;
    import mortal.component.window.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.copy.guildCopy.renderer.*;
    import mortal.mvc.interfaces.*;

    public class GuildCopyEndPanel extends Window
    {
        private var _list:GTileList;
        private var _uiCreateOver:Boolean = false;
        private var _bigX:GBitmap;
        private var _numtTimes:BitmapNumberText;
        private var _numContribution:BitmapNumberText;
        private var _numResource:BitmapNumberText;
        private var _numCoin:BitmapNumberText;
        private var _txtDesc:GTextFiled;
        private var _data:SGuildBossRewardInfo;
        private static var _instance:GuildCopyEndPanel;

        public function GuildCopyEndPanel(param1:ILayer = null)
        {
            super(param1);
            if (_instance)
            {
                throw new Error("single");
            }
            setSize(829, 499);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            var _loc_1:* = UIFactory.gImageBitmap(ImagesConst.GuildCopyEndBg, 0, 0);
            this.addChildAt(_loc_1, 0);
            pushUIToDisposeVec(_loc_1);
            LoaderHelp.addResCallBack(ResFileConst.guildCopyEndPanel, this.showSkin);
            return;
        }// end function

        private function showSkin() : void
        {
            var _loc_6:SPlayerItem = null;
            pushUIToDisposeVec(UIFactory.bg(280, 242, 332, 3, this, ImagesConst.SplitLine));
            pushUIToDisposeVec(UIFactory.bg(280, 312, 332, 3, this, ImagesConst.SplitLine));
            pushUIToDisposeVec(UIFactory.textField("" + Language.getString(70931), 433, 125, 80, 24, this, GlobalStyle.textFormatBai.setSize(14)));
            pushUIToDisposeVec(UIFactory.bitmap(ImagesConst.PackItemBg1, 366, 185, this));
            pushUIToDisposeVec(UIFactory.bitmap(ImagesConst.PackItemBg1, 366, 257, this));
            pushUIToDisposeVec(UIFactory.bitmap(ImagesConst.PackItemBg1, 366, 329, this));
            var _loc_1:* = UIFactory.bitmap(ImagesConst.ContributionBig, 388, 328 - 72 - 72 + 5, this);
            _loc_1.width = 36;
            _loc_1.height = 36;
            pushUIToDisposeVec(_loc_1);
            var _loc_2:* = UIFactory.bitmap(ImagesConst.ResourceBig, 388, 328 - 72 + 5, this);
            _loc_2.width = 36;
            _loc_2.height = 36;
            pushUIToDisposeVec(_loc_2);
            var _loc_3:* = UIFactory.bitmap(ImagesConst.JinbiBig, 388, 328 + 5, this);
            _loc_3.width = 36;
            _loc_3.height = 36;
            pushUIToDisposeVec(_loc_3);
            pushUIToDisposeVec(UIFactory.bitmap(ImagesConst.GuildCopyContribute, 507, 180, this));
            pushUIToDisposeVec(UIFactory.bitmap(ImagesConst.GuildCopyResource, 507, 252, this));
            pushUIToDisposeVec(UIFactory.bitmap(ImagesConst.GuildCopyCoin, 507, 324, this));
            pushUIToDisposeVec(UIFactory.bitmap(ImagesConst.GuildCopyItem, 507 - 179, 396, this));
            this._bigX = UIFactory.bitmap(ImagesConst.GuildCopyXBig, 0, 123, this);
            pushUIToDisposeVec(UIFactory.bitmap(ImagesConst.GuildCopyX, 460, 205, this));
            pushUIToDisposeVec(UIFactory.bitmap(ImagesConst.GuildCopyX, 460, 277, this));
            pushUIToDisposeVec(UIFactory.bitmap(ImagesConst.GuildCopyX, 460, 349, this));
            this._numtTimes = UIFactory.bitmapNumberText(0, 123, "GuildCopyNumBig.png", 55, 77, 0, this, 9);
            this._numContribution = UIFactory.bitmapNumberText(484, 200, "GuildCopyNum.png", 24, 32, -6, this, 9);
            this._numResource = UIFactory.bitmapNumberText(484, 273, "GuildCopyNum.png", 24, 32, -6, this, 9);
            this._numCoin = UIFactory.bitmapNumberText(484, 344, "GuildCopyNum.png", 24, 32, -6, this, 9);
            this._txtDesc = UIFactory.gTextField("", 360, 467, 340, 22, this, GlobalStyle.textFormatHuang.setSize(14));
            this._list = UIFactory.tileList(350, 395, 350, 46, this);
            this._list.rowHeight = 46;
            this._list.columnWidth = 46;
            this._list.setStyle("cellRenderer", GuildCopyRewardItemListCellRenderer);
            var _loc_4:Array = [];
            var _loc_5:int = 0;
            while (_loc_5 < 4)
            {
                
                _loc_4.push(new Object());
                _loc_5++;
            }
            this._list.dataProvider = new DataProvider(_loc_4);
            this._list.drawNow();
            if (this._data == null)
            {
                this._data = new SGuildBossRewardInfo();
                this._data.color = 4;
                this._data.contribution = 120;
                this._data.resource = 240;
                this._data.coin = 15000;
                _loc_4 = [];
                _loc_5 = 0;
                while (_loc_5 < 4)
                {
                    
                    _loc_6 = new SPlayerItem();
                    _loc_6.itemCode = 110000000 + _loc_5;
                    _loc_6.itemAmount = 2;
                    _loc_4.push(_loc_6);
                    _loc_5++;
                }
                this._data.items = _loc_4;
            }
            this._uiCreateOver = true;
            this.update();
            return;
        }// end function

        private function update() : void
        {
            if (!this._uiCreateOver || this._data == null)
            {
                return;
            }
            this.playEffect();
            var _loc_1:* = Language.getStringByParam(70932, GameDefConfig.instance.getGuildBossColorName(this._data.color), HTMLUtil.addColor("X" + this._data.color, GlobalStyle.colorLv));
            this._txtDesc.htmlText = HTMLUtil.addColor(_loc_1, GlobalStyle.colorHuang);
            this._numtTimes.text = this._data.color.toString();
            this._numResource.text = (this._data.resource / this._data.color).toString();
            this._numContribution.text = (this._data.contribution / this._data.color).toString();
            this._numCoin.text = (this._data.coin / this._data.color).toString();
            this._list.dataProvider = new DataProvider(this._data.items.concat());
            this._list.drawNow();
            setTimeout(this.flyToPack, 2000);
            return;
        }// end function

        private function flyToPack() : void
        {
            var _loc_2:GuildCopyRewardItemListCellRenderer = null;
            var _loc_1:* = this._list.dataProvider.length;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_1)
            {
                
                _loc_2 = this._list.itemToCellRenderer(this._list.dataProvider.getItemAt(_loc_3)) as GuildCopyRewardItemListCellRenderer;
                if (_loc_2)
                {
                    FlyToNavbarTool.flyToBackPack(_loc_2.itemBitmapData, _loc_2.pos);
                }
                _loc_3++;
            }
            return;
        }// end function

        public function setData(param1:SGuildBossRewardInfo) : void
        {
            this._data = null;
            this._data = param1;
            this.update();
            return;
        }// end function

        public function playEffect() : void
        {
            var _loc_1:* = UICompomentPool.getUICompoment(SWFPlayer);
            _loc_1.move(680, this._numtTimes.y);
            _loc_1.timeRate = 1;
            addChild(_loc_1);
            _loc_1.load("GuildCopyRunPoint.swf", ModelType.NormalSwf, null);
            var _loc_2:* = this._numCoin.x;
            var _loc_3:* = this._numCoin.y;
            var _loc_4:* = new TimelineMax();
            _loc_4.appendMultiple([new TweenMax(this._bigX, 0.8, {x:596, ease:Cubic.easeInOut}), new TweenMax(this._numtTimes, 0.8, {x:680, ease:Back.easeInOut})]);
            _loc_4.appendMultiple([new TweenMax(_loc_1, 1.5, {sceneX:_loc_2, sceneY:_loc_3, bezierThrough:[{x:500, y:200}]})]);
            _loc_4.appendMultiple([new TweenMax(this._numResource, 1, {value:this._data.resource}), new TweenMax(this._numContribution, 1, {value:this._data.contribution}), new TweenMax(this._numCoin, 1, {value:this._data.coin})]);
            _loc_4.play();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._data = null;
            this._list.dispose(param1);
            this._bigX.dispose(param1);
            this._numtTimes.dispose(param1);
            this._numContribution.dispose(param1);
            this._numResource.dispose(param1);
            this._numCoin.dispose(param1);
            this._txtDesc.dispose(param1);
            this._list = null;
            this._bigX = null;
            this._numtTimes = null;
            this._numContribution = null;
            this._numResource = null;
            this._numCoin = null;
            this._txtDesc = null;
            return;
        }// end function

        override protected function updateBtnSize() : void
        {
            if (_closeBtn)
            {
                _closeBtn.x = this.width - _closeBtn.width - 70;
                _closeBtn.y = 65;
            }
            return;
        }// end function

        public static function get instance() : GuildCopyEndPanel
        {
            if (!_instance)
            {
                _instance = new GuildCopyEndPanel;
            }
            return _instance;
        }// end function

    }
}
